<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%
	JSONObject result = new JSONObject();
	//获取数据
	String vCode = request.getParameter("vCode");
	if (null == vCode) {
		result.put("status", -1);
		result.put("msg", "请输入验证码");
		out.println(result);
		return;
	}
	//判断验证码
	String sessionCode = (String) session.getAttribute("vCode");

	if (null == sessionCode) {
		result.put("status", -1);
		result.put("msg", "验证码已失效");
		out.println(result);
		return;
	}
	if (!sessionCode.toLowerCase().equals(vCode.toLowerCase())) {
		result.put("status", -1);
		session.removeAttribute(vCode);
		result.put("msg", "验证码错误，请刷新验证码重试");
		out.println(result);
		return;
	}
	String phone = request.getParameter("phone");
	String question_name = request.getParameter("question_name");
	String question = request.getParameter("question");

	if (nullOrEmpty(phone)) {
		result.put("status", -1);
		result.put("msg", "请输入手机号码");
		out.println(result);
		return;
	}
	if (nullOrEmpty(question_name)) {
		result.put("status", -1);
		result.put("msg", "请输入您的姓名");
		out.println(result);
		return;
	}
	if (nullOrEmpty(question)) {
		result.put("status", -1);
		result.put("msg", "请输入您的问题");
		out.println(result);
		return;
	}
	//转换时间

	String questionTime = formatDate("yyyy-MM-dd HH:mm:ss", new Date());
	String qa_id = getGuid();
	String sql = "INSERT INTO APP_QA (qa_id,question_name,phone,question,status,create_time,question_ip) values (?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?)";
	int i = executeUpdate(sql,
			new Object[] { qa_id, question_name, phone, question, "A", questionTime, getIpAddr(request) });
	if (i >= 1) {
		result.put("status", 200);
		result.put("msg", "提交成功");
		out.println(result);
	} else {
		result.put("status", -1);
		result.put("msg", "提交失败，请重试");
		out.println(result);
	}
%>